/* 
2020 06 22
lili
 医院级别 
*/
// 引入数据文件  前端测试用
medicalTitle = [
    {
        "name":"主任医师","code":"1"
    },{
        "name":"副主任医师","code":"2"
    },{
        "name":"主治医师","code":"3"
    }
]
hosGrade = [
    {
        "name":"三甲","code":"1"
    },{
        "name":"三级","code":"2"
    },{
        "name":"二甲","code":"3"
    },{
        "name":"二级","code":"4"
    },{
        "name":"一甲","code":"5"
    },{
        "name":"一级","code":"6"
    },{
        "name":"民营医院","code":"7"
    }
]
price = [
    {
        "name":"从低到高","code":"1"
    },{
        "name":"从高到低","code":"2"
    }
]

$(function(){
    var medicalTitleData = medicalTitle,
    gradeData = hosGrade,
    priceData = price; // 数据
    // 点击 科室
    function serviceFun(indexMedicalTitle,indexHosGrade,indexPrice){
        // 当前选中的 医院级别 
        var _indexMedicalTitle = indexMedicalTitle,
            _indexHosGrade = indexHosGrade,
            _indexPrice = indexPrice; 
        if(_indexMedicalTitle == ''){_indexMedicalTitle = 0; }
        if(_indexHosGrade == ''){_indexHosGrade = 0; }
        if(_indexPrice == ''){_indexPrice = 0; }

        $("#fixSelect").html('');
            var popHtml = '<div class="fix-select-all">';
            popHtml += '<div class="fix-select-all-in list-flex-column">';
            popHtml += '<div class="fix-select-all-list list-bd">';
            popHtml += '<div id="medicalTitle" class="fix-select-all-li">';
            popHtml += '<h6>医生职称</h6>';
            popHtml += '<ul class="list-flex-br">';
            popHtml += '<li class="list-br3" data-code="0"><a href="javascript:;">全部</a></li>';
            $.each(medicalTitleData, function (idx, item) {
                popHtml += '<li class="list-br3" data-code="'+item.code+'"><a href="javascript:;">'+item.name+'</a></li>';
            });
            popHtml += '</ul>';
            popHtml += '</div>';

            popHtml += '<div id="hosGrade" class="fix-select-all-li">';
            popHtml += '<h6>医院等级</h6>';
            popHtml += '<ul class="list-flex-br">';
            popHtml += '<li class="list-br3" data-code="0"><a href="javascript:;">全部</a></li>';
            $.each(gradeData, function (idx, item) {
                popHtml += '<li class="list-br3" data-code="'+item.code+'"><a href="javascript:;">'+item.name+'</a></li>';
            });
            popHtml += '</ul>';
            popHtml += '</div>';

            popHtml += '<div id="price" class="fix-select-all-li">';
            popHtml += '<h6>价格排序</h6>';
            popHtml += '<ul class="list-flex-br">';
            popHtml += '<li class="list-br3" data-code="0"><a href="javascript:;">全部</a></li>';
            $.each(priceData, function (idx, item) {
                popHtml += '<li class="list-br3" data-code="'+item.code+'"><a href="javascript:;">'+item.name+'</a></li>';
            });
            popHtml += '</ul>';
            popHtml += '</div>';

            popHtml += '</div>';
            popHtml += '<div class="fix-select-all-btns"> <ul class="list-flex iphonex-bottom"> <li class="list-bd"> <div id="btnRemake" class="btn-one">重制</div> </li> <li class="list-bd"> <div id="btnSubmit" class="btn-two">完成</div> </li> </ul> </div>';
            popHtml += '</div>';
            popHtml += '</div>';

            
        $("#fixSelect").html(popHtml);
        // 页面距顶部距离
        var top = $('.fix-top').height();
        $('#fixSelect .fix-select-all').css('top',top+'px');
        // 选中当前选择的
        $('#medicalTitle li').each(function(){
            var curText = $(this).attr('data-code');
            if(curText == _indexMedicalTitle){
                $(this).addClass('curr');
            }
        })
        $('#hosGrade li').each(function(){
            var curText = $(this).attr('data-code');
            if(curText == _indexHosGrade){
                $(this).addClass('curr');
            }
        })
        $('#price li').each(function(){
            var curText = $(this).attr('data-code');
            if(curText == _indexPrice){
                $(this).addClass('curr');
            }
        })
    }

    // 筛选 click
    $('#selectAllBtn').click(function(){
        if(!$(this).hasClass('curr')){
            $(this).addClass('curr').siblings('.nav-li').removeClass('curr');
            // 当前选中
            var indexMedicalTitle = $(this).attr('data-medicalTitle'),
                indexHosGrade = $(this).attr('data-hosGrade'),
                indexPrice = $(this).attr('data-price'); 
            serviceFun(indexMedicalTitle,indexHosGrade,indexPrice);
        }else{
            $("#fixSelect").html('');
            $('#selectAllBtn').removeClass('curr');
        }
    })
    // 点击 选中标签
    $("#fixSelect").on('click','.fix-select-all-li li',function(){
        $(this).addClass('curr').siblings('li').removeClass('curr');
    });
    // 点击 完成 按钮
    $("#fixSelect").on('click','#btnSubmit',function(){
        // 选中 
        var curMedicalTitle = $('#medicalTitle li.curr').attr('data-code'),
            curHosGrade = $('#hosGrade li.curr').attr('data-code'),
            curPrice = $('#price li.curr').attr('data-code');
        $('#selectAllBtn').attr('data-medicalTitle',curMedicalTitle);
        $('#selectAllBtn').attr('data-hosGrade',curHosGrade);
        $('#selectAllBtn').attr('data-price',curPrice);
        
        // 关闭弹框 清空就是关闭
        $("#fixSelect").html('');
        $('#selectAllBtn').removeClass('curr'); 
    })
    // 点击 重置 按钮
    $("#fixSelect").on('click','#btnRemake',function(){
        var indexMedicalTitle = 0,
            indexHosGrade = 0,
            indexPrice = 0; 
        serviceFun(indexMedicalTitle,indexHosGrade,indexPrice);

    })

})






